<template>
  <div class="data-container">
    <div class="tab-panel">
      <div class="slot">
        <slot></slot>
      </div>
      <p class="text">{{ title }}</p>
      <BarChart ref="BarChart + id" :chartData="chartData"></BarChart>
    </div>
  </div>
</template>

<script>
import BarChart from '@/components/ECharts/BarChart2.vue'

export default {
  name: 'panel1',
  props: {
    title: { type: String, default: '' },
    data: { type: Object, default: () => {} },
    id: { type: String, default: '' },
  },
  components: { BarChart },
  data() {
    return {
      chartData: {},
    }
  },
  mounted() {
    this.initEcharts()
  },
  methods: {
    // 初始化图表
    initEcharts() {
      this.chartData = {
        x: this.data.key,
        series: [
          {
            name: this.title,
            data: this.data.val,
          },
        ],
      }
    },
    onResize() {
      this.$refs[BarChart + this.id].onResize()
    },
  },
}
</script>
<style lang="scss" scoped>
$bgColor: #060a22;
$mainColor: #68cee0;
$mainColorOpcity: rgba(104, 206, 224, 0.3);
.data-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  padding: 20px;
  overflow: hidden;
}

.tab-panel {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  overflow: hidden;
  position: relative;
  .text {
    width: 100%;
    color: #ffffff;
  }
}

.slot {
  position: absolute;
  top: 4px;
  right: 0;
}
</style>
